package com.michael.assist.utils;

import org.springframework.stereotype.Component;

@Component
public class CodeUtil {

    public String cnToUnicode(String cn) {
        char[] chars = cn.toCharArray();
        StringBuilder returnStr = new StringBuilder();
        for (char aChar : chars) {
            if (isChineseCharacter(aChar)) {
                returnStr.append("\\u").append(Integer.toString(aChar, 16));
            } else {
                returnStr.append(aChar);
            }
        }
        return returnStr.toString();
    }

    public boolean isChineseCharacter(char c) {
        return c >= 0x4E00 && c <= 0x9FA5;// 根据字节码判断
    }
}
